package com.seafwg.eduservice.controller.front;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.seafwg.commonutils.R;
import com.seafwg.eduservice.entity.EduCourse;
import com.seafwg.eduservice.entity.EduTeacher;
import com.seafwg.eduservice.service.EduCourseService;
import com.seafwg.eduservice.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
@Api(value = "前端首页热门课程和名师查询")
@RequestMapping("/eduservice/indexfront")
public class IndexFrontController {
    @Autowired
    private EduCourseService eduCourseService;

    @Autowired
    private EduTeacherService eduTeacherService;

    /**
     * 查询前8条热门课程，前4名名师
     * @return
     */
    @ApiOperation(value = "查询前8条热门课程，前4名名师")
    @GetMapping("/index")
    public R index() {
        //查询前8条热门课程信息
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 8");
        List<EduCourse> courseList = eduCourseService.list(wrapper);

        //查询4名名师
        QueryWrapper<EduTeacher> wrapperT = new QueryWrapper<>();
        wrapperT.orderByDesc("id");
        wrapperT.last("limit 4");
        List<EduTeacher> teacherList = eduTeacherService.list(wrapperT);

        return R.ok().data("courseList", courseList).data("teacherList", teacherList);
    }

}
